﻿#region
using System;
using System.Collections;
using System.Data;
using System.Web.UI.WebControls;
using ZhongLangDB;
#endregion

namespace ZHONGLANGWEBUI.ZHONGLANG.SET
{
    public partial class CONFIG : TT_BasePageList
    {
        protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { pageInit(); dgListDo("查询初次", ""); } }
        
        #region pageInit
        protected override void pageInit()
        {
             
        }
        #endregion

        #region pageBind 
        protected DataTable proSDListQuery(int iType)
        {
            SortedList SDList = new SortedList();
            SDList["CONFIGNAMELINK"] = txtQCONFIGNAME.Text; 
            DataTable dt = pgShow.proQueryData(SDList, "PROTT_SYS_CONFIGQUERY", iType);
            return dt;
        }

        protected override void pageBind()
        {
            DataTable dt = proSDListQuery(1);
            DataView dv = dt.DefaultView;
            if (ViewState["SortExpression"] != null) { dv.Sort = GetSortDirectiont(ViewState["SortExpression"].ToString(), ViewState["SortDirection"].ToString()); }
            dgList.DataSource = dv; dgList.DataBind();  
        }
        #endregion
          
        #region pageOpt 
        protected override void dgListDo(string strCommandName, string strCommandArgument)
        {
            #region dgBase 
            if (strCommandName == "查询初次") { pgShow.CurrPageIndex = 1; pgShow.CurrPageSize = REQPAGECOUNT; pageBind(); }
            if (strCommandName == "查询") { pageBind(); }
            if (strCommandName == "导出") { proExpData(proSDListQuery(2), dgList); } 
            #endregion

            #region 修改
            if (strCommandName == "修改")
            {
                string strBack = "";
                foreach (GridViewRow gr in dgList.Rows)
                { 
                    if (dgList.DataKeys[gr.RowIndex]["CONFIGID"].ToString() == strCommandArgument)
                    {
                        string strSql = "UPDATE TT_SYS_CONFIG SET CONFIGVALUE='" + DBPark.proPrameCheck(((TextBox)(gr.FindControl("txtECONFIGVALUE"))).Text) + "',"
                                      + " UPDATEMANID = "+CURREMP.USERID+",UPDATEMANNAME='"+CURREMP.USERNAME+"',UPDATETIME=GETDATE()"
                                      + " WHERE CONFIGID="+ strCommandArgument ;
                        strBack = DBPark.proSetDB(null, strSql);
                        break;
                    }
                }
                pageBind(); jsMessage("更新成功！");
            }
            #endregion 
        }
        #endregion  
    }
}